package qrcodeGeneretor;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import colorChanger.ColoredQRCode;

public class Main {
	public static void main(String[] args) throws FileNotFoundException,
			IOException {
//		 new ColoredQRCode("Images/ColoredAndTraditional/raul1.png","Images/ColoredAndTraditional/raul2.png","png").getColoredQRCode().writhImage("raul");
		 
				// 1716 caracteres é meu maximo
		// String cemCaracteres =
		// "0987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321";
		String data = Text.getRaulSeixasSong2019();
		String fileName = "raulSeixas";
		System.out.println("Characteres quantity " + data.length());
		generateQRCODECloeredAndDEfaults(data, fileName);
		System.out.println(data);
		// generateQRCODECloeredAndDEfaults(getLeonardoDaVInciCitation(),
		// "Leonardo de Vinci");
		// generateQRCODECloeredAndDEfaults(getMartinLuterKingCitation(),
		// "Martin Luther King, Jr");
		// generateQRCODECloeredAndDEfaults(getJoseAntonioCitation(),
		// "JosÃ© Antonio");
		// generateQRCODECloeredAndDEfaults(QRCODE.NUMERIC_STRING_2001,"2001 numeros");
		// generateQRCODECloeredAndDEfaults(QRCODE.NUMERIC_STRING_2001+"1"+QRCODE.NUMERIC_STRING_2001,"4003 numeros");

	}

	private static void generateQRCODECloeredAndDEfaults(String data,
			String fileName) throws FileNotFoundException, IOException {
		final String defaultPath = "Images/ColoredAndTraditional/";
		// generate default qrcode
		QRCODE.generateQRCODE(data, defaultPath + fileName + "_defaultQRCODE");

		// generating primary and secundary qrcode
		List<String> primaryAndSecundaryData = getPrimaryAndSecundaryData(data);
		String primaryData = primaryAndSecundaryData.get(0);
		String secundaryData = primaryAndSecundaryData.get(1);
		String primaryPath = defaultPath + fileName + "_primaryQRCODE";
		String secundaryPath = defaultPath + fileName + "_secundaryQRCODE";
		QRCODE.generateQRCODE(primaryData, primaryPath);
		QRCODE.generateQRCODE(secundaryData, secundaryPath);

		// generating colored QRCODE
		ColoredQRCode coloredQRCode = new ColoredQRCode(primaryPath + ".png",
				secundaryPath + ".png", "png");
		coloredQRCode.getColoredQRCode().writhImage(
				defaultPath + fileName + "_coloredQRCODE");
	}

	private static List<String> getPrimaryAndSecundaryData(String data) {
		char[] dataCharArray = data.toCharArray();
		String primaryBarcodeData = "";
		String secondaryBarcodeData = "";
		List<String> primaryAndSecundaryData = new ArrayList<String>();
//		if (dataCharArray.length < 1710) {
			for (int i = 0; i < dataCharArray.length; i++) {
				if (i < dataCharArray.length / 2) {
					primaryBarcodeData = primaryBarcodeData + dataCharArray[i];
				} else {
					secondaryBarcodeData = secondaryBarcodeData
							+ dataCharArray[i];
				}
			}
//		}else{
//			for (int i = 0; i < dataCharArray.length; i++) {
//				if (i < 1330) {
//					primaryBarcodeData = primaryBarcodeData + dataCharArray[i];
//				} else {
//					secondaryBarcodeData = secondaryBarcodeData
//							+ dataCharArray[i];
//				}
//			}
//		}
//		System.out.println(primaryBarcodeData+"\n\n");
//		System.out.println(secondaryBarcodeData+"\n\n");
		primaryAndSecundaryData.add(primaryBarcodeData);
		primaryAndSecundaryData.add(secondaryBarcodeData);

		return primaryAndSecundaryData;
	}

}
